<template>
    <div>
        <table>
            <tr>
                <td>食谱标题</td>
                <td>
                    <input type="text" v-model="data.spbt">
                </td>
            </tr>
            <tr>
                <td>食谱分类</td>
                <td>
                    <select v-model="data.lxid">
                        <option value="0">请选择</option>
                        <option value="1">川菜</option>
                        <option value="2">鲁菜</option>
                        <option value="3">粤菜</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>食谱图片</td>
                <td>
                   <input type="file" @change="update">
                   <img src="https://localhost:7189//pic/2236ca4f-703e-43ea-b355-8685bb36185111.jpg" alt="" >
                   
                </td>
            </tr>
            <tr>
                <td>标签</td>
                <td>
                    <input type="text" v-model="data.fzr">
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" @click="add">
                </td>
            </tr>
        </table>

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';

const data=ref({
    "spid": 0,
  "spbt": "string",
  "lxid": 0,
  "img": "4205e7ca-2fc5-494f-b04c-8ddcab30f84b7",
  "fzr": "string"
})
 
const  update=(a:any)=>{
 
   
  
    axios.get("https://localhost:7189/api/tp/phon",{params:data.value.img}).then(res=>{
            data.value=res.data
    })


}
const add=()=>{
        if(data.value.spbt==""){
            alert("食谱标题不能为空")
            return
        }
        if(data.value.img=="string"){
            alert("食谱封面不能为空")
            return
        }
        if(data.value.lxid==0){
            alert("食谱分类不能为空")
            return
        }
        if(data.value.fzr==""){
            alert("食谱标签不能为空")
            return
        }


    axios.post("https://localhost:7189/api/sp/add",data.value).then(res=>{
        if(res.data>0){
            alert("添加成功");
            location.href="/xs"
        }else{
            alert("添加失败")
        }
    })
}



</script>

<style scoped>

</style>